package com.rr;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

public class LoadingCacheTest {
    public static void main(String[] args) throws ExecutionException {
        LoadingCache<String,String> loadingCache = CacheBuilder.newBuilder()
                .initialCapacity(2)
                .maximumSize(2)
                .expireAfterWrite(1, TimeUnit.HOURS)
                .build(new CacheLoader<String, String>() {

                    @Override
                    public String load(String s) {
                        System.out.println("加载key:" + s);
                        return s;
                    }
                });
        System.out.println(loadingCache.get("a"));
    }
}
